{% extends "../master.html" %}
{% block hfm_css %}
<style type="text/css">
    .layui-form-label{
        width: 100px;
        background-color: rgba(247, 247, 247, 0.84);
    }
    .layui-input-block{
        margin-left: 100px;
        min-height: 30px;
    }
</style>
{% end %}
{% block page_content %}
<div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="">资产管理</a>
        <a><cite>资产列表</cite></a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body layui-form layui-row layui-col-space10" id="projcet-query"
                    lay-filter="projcet-query">
                    <form class="layui-form layui-col-md4">
{#                        <!--{% raw xsrf_form_html() %}-->#}
                        <label class="layui-form-label">模糊查询</label>
                        <div class="layui-input-block">
                            <input type="text" name="condition" placeholder="" autocomplete="off" class="layui-input">
                        </div>
                    </form>
                    <div class="layui-input-inline layui-show-xs-block TaskTable">
                        <button class="layui-btn" lay-submit="" lay-filter="sreach" data-type="reload">查询</button>
                    </div>
                </div>
                <xblock>
                    <div class="layui-card-header AssetTable">
                        <button class="layui-btn" onclick="xadmin.open('安全扫描','/asset/vulnscan',850,500)">
                            <i class="layui-icon layui-icon-auz"></i>安全扫描
                        </button>
                    </div>
                </xblock>
                <!-- task table-->
                <div class="layui-card-body">
                    <table class="layui-table layui-form" id="task_table" lay-filter="option"></table>
                </div>
                <!--task table-->
            </div>
        </div>
    </div>
</div>
{% block sechfm_js %}
    <script type="text/html" id="barDemo">
      <a class="layui-btn layui-btn-xs" lay-event="edit">详情</a>
      <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="start">删除</a>
    </script>
{% end %}

<script>
//var xsrf = $('input[name="_xsrf"]').val();
layui.use('table', function() {
    var table = layui.table;
    //方法级渲染
    table.render({
        elem: '#task_table'
        , url: "/task/list"
        , method: 'post'
        //,where: {'xsrf_token':xsrf}
        , cols: [[
            {checkbox: true, fixed: true}
            , {field: 'host', title: '主机', align: 'center'}
            , {field:'title', title: '标题', align: 'center', unresize: true}
            , {field:'status', title: '状态', align: 'center', unresize: true}
            , {field: 'ipaddr', title: 'IP地址', align: 'center', unresize: true}
            , {field: 'port', title: '端口', align: 'center', unresize: true}
            , {field: 'os', title: '操作系统',align: 'center', unresize: true}
            , {field: 'start_at', title: '扫描时间',align: 'center', unresize: true}
            ,{ title: '高级选项',fixed: 'right', align:'center', toolbar: '#barDemo', width: 120}
        ]]
        , id: 'testReload'
        , page: true
        , limit: 15
        , text: {none: '目前暂无数据'}
    });
    //头工具栏事件
    table.on('tool(option)', function(obj){
        var checkStatus = obj.data;
        console.log(checkStatus)
    });
    // 操作
    var $ = layui.$, active = {
        // 删除任务
        deletechoice: function(){ //获取选中数据
                var checkStatus = table.checkStatus('testReload')
                ,data = checkStatus.data
                ,list=new Array();
                for(var i=0;i<data.length;i++){
                    list[i] = data[i].taskname
                }
                layer.confirm('该操作为敏感操作<br>点击确认删除任务【'+data[0].taskname+'】该操作删除后无法恢复！',function(index){
                    $.ajax({
                        type: "delete",
                        url: '/task/list',
                        async: true,
                        data:{
                            task_list:JSON.stringify(list),
                            action:'start',
                        },
                        success:function (data) {
                            layer.msg(data.msg);
                            setTimeout((function () {
                                location.replace(location.href)
                            }));
                        }
                    });
                })
            }
        ,reload: function() {
            //执行重载
            //alert($('#id_task').val());
            table.reload('testReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    taskname: $('#id_task').val()
                    ,status: $("#id_status option:selected").val()
                }
            });
            }
        };
        $('.TaskTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

})
</script>

{% end %}